

package ListHandling;

import static ListHandling.ClientListHandling.in;
import basic.Bike;
import basic.BikeType;
import basic.MTBBike;
import basic.RegularBike;
import basic.SpecialBike;
import exceptions.ObjectNotFound;
import java.util.Scanner;
import lists.Lists;

public class BikeListHandling {
    
    public static Scanner in = new Scanner(System.in);
        
    // ****************************************************************
    public static Bike addBike() {

        Bike helper = null;
        System.out.println("What kind of bike you want to add ?");
        System.out.println("1 - REGULAR bike");
        System.out.println("2 - MTB bike");
        System.out.println("3 - SPECIAL bike");
        System.out.println("0 - to break");
//        int j=99;
//        while (j!=0) {

        int j = in.nextInt();

        switch (j) {
            case 1:
                helper = addRegBike();
                break;
            case 2:
                helper = addMTBBike();
                break;
            case 3:
                helper = addSpecBike();
                break;
            case 0:
                break;
            default:
                System.out.println("No option with entered number!");
                break;

        }

        return helper; 
        }
    
    
        // ****************************************************************
        private static RegularBike addRegBike() {

        RegularBike helper = new RegularBike();
        System.out.println("Enter model of bike: ");
        helper.setModel(in.next());
        System.out.println("Wheel size: ");
        helper.setWheelSize(in.nextInt());

        return helper;

        }

    // ****************************************************************
    private static MTBBike addMTBBike() {

        MTBBike helper = new MTBBike();
        System.out.println("Enter model of bike: ");
        helper.setModel(in.next());
        System.out.println("Wheel size: ");
        helper.setWheelSize(in.nextInt());
        System.out.println("Shifts: ");
        helper.setShifts(in.nextInt());
        return helper;
    }

    // ****************************************************************
    private static SpecialBike addSpecBike() {

        SpecialBike helper = new SpecialBike();
        System.out.println("Enter model of bike: ");
        helper.setModel(in.next());
        System.out.println("Wheel size: ");
        helper.setWheelSize(in.nextInt());
        System.out.println("Shifts: ");
        helper.setShifts(in.nextInt());
        System.out.println("Choose specific bike type: ");

        int k = 99;
        while ((k != 1) & (k != 2) & (k != 3)) {

            System.out.println("1 - DOWNHILL bike");
            System.out.println("2 - TRIAL bike");
            System.out.println("3 - ENDURO bike");

            k = in.nextInt();
            switch (k) {
                case 1:
                    helper.setType(BikeType.DOWNHILL);
                    break;
                case 2:
                    helper.setType(BikeType.TRIAL);
                    break;
                case 3:
                    helper.setType(BikeType.ENDURO);
                    break;
                default:
                    System.out.println("No option with entered number! Try agin");
                    break;
            }

        }

        return helper;
    }
    
    // ****************************************************************
    public static void deleteBike() throws ObjectNotFound {
        System.out.println("Enter ID of bike you want to delete: ");
        int p = in.nextInt();
        if (Lists.bList.ifExist(p)<0 ) throw new ObjectNotFound();
        else Lists.bList.delete(p);
        System.out.println("Successfully deleted bike !");
    }
    
    
    // ****************************************************************
    public static void showBikeList() {

        System.out.println("BIKE LIST\n");
        System.out.println(String.format("%4s %20s %10s %6s %10s %6s %10s",
                "ID", "MODEL", "WHEELSIZE", "TOTAL", "SERVICE", "SHIFTS", "TYPE"));
        Lists.bList.show();
    }
    
    // ****************************************************************
    public static void sortBikeList(){
        Lists.bList.sort();
        System.out.println("Successfully sorted!");
    }
    
    
    public static void fill(){
        
        MTBBike b1 = new MTBBike();
        b1.setModel("Kross A9");
        b1.setWheelSize(26);
        b1.setShifts(29);
        
        SpecialBike b2 = new SpecialBike();
        b2.setModel("Specialized FSR");
        b2.setShifts(18);
        b2.setWheelSize(26);
        b2.setType(BikeType.DOWNHILL);
        
        Lists.bList.add(b1);
        Lists.bList.add(b2);
    }
    
    
}
